var util = require('../../utils/util.js')
const app = getApp()
let jinbiShareLgImg = ''
let jinbiShareText = ''
Page({
  inputValue: '',
  data: {
    jinbi_moreJinbi: false,
    videoSrc: null,
    posterSrc: null,
    imgSrc: null
  },
  onShow: function () {
    this.tabBar(); // 获取当前时间显示到首页
  },
  onLoad() {
    if(!app.globalData.isRegistered){
      app.selecteUser().then(res=>{
        app.globalData.isRegistered = res
      })
    }
    this.getSystemController()//异步获取系统控制变量
    this.selectTopImg() // 加载顶部多媒体展示到页面
    this.select_lookVideos_qiandao()
  },
  //异步获取系统控制变量
  getSystemController() {
    if (app.globalData.controller == null) {
      app.getSystemController().then(res => {
        this.setData({
          jinbi_moreJinbi: res.jinbi_moreJinbi
        })
      })
    } else {
      this.setData({
        jinbi_moreJinbi: app.globalData.controller.jinbi_moreJinbi
      })
    }
  },
  // 加载顶部多媒体展示到页面
  selectTopImg() {
    if (app.globalData.getGlobalShareMedia == null) {
      app.getGlobalShareMedia().then(res => {
        jinbiShareLgImg = res.jinbiShareLgImg
        jinbiShareMinImg = res.jinbiShareMinImg
        jinbiShareText = res.jinbiShareText
      })
    } else {
      jinbiShareLgImg = app.globalData.getGlobalShareMedia.jinbiShareLgImg,
        jinbiShareMinImg = app.globalData.getGlobalShareMedia.jinbiShareMinImg,
        jinbiShareText = app.globalData.getGlobalShareMedia.jinbiShareText
    }
  },
  // 设置看视频数据表
  select_lookVideos_qiandao() {
    wx.cloud.callFunction({
      name: 'lookvideosqiandao',
      data: {
        tag: 'select',
        _updateTime: util.formatTime(new Date()).slice(0, 10)
      }
    })
  },

  // 更多金币平台
  moreJinbi() {
    wx.navigateToMiniProgram({
      appId: 'wx83ed21db6ad34120',
      path: '/pages/news/news',

      envVersion: 'release',
      success(res) {
        // 打开成功
      }
    })
  },


  tabBar() {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 1
      })
    }
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      
      title: `${app.globalData.userInfo.nickName}带你${jinbiShareText}`,
      path: `/pages/news/news?shangjiOpenId=${app.globalData.userInfo._openid}`,
      imageUrl: jinbiShareLgImg,
    }
  },

})